import { defineStore } from 'pinia'
import { ref } from 'vue'
import { User } from '../type/user'

// 测试用户数据
const testUser: User = {
  id: '123456',
  username: 'testuser',
  avatar: '',
  gender: 1,
  description: '测试用户',
  birthday: '2025-06-01',
  address: '测试地址',
  userCover: '',
  trendCount: 10,
  followerCount: 100,
  fanCount: 50,
}
const isLoggedIn = ref(false)

export const useProfileStore = defineStore('user', () => {
  const user = ref({} as User)

  // 模拟登录方法
  async function login(account: string, password: string) {
    return new Promise<void>((resolve) => {
      setTimeout(() => {
        user.value = testUser
        isLoggedIn.value = true

        resolve()
      }, 500) // 模拟网络延迟
    })
  }

  function getUserInfo() {
    // 调用接口获取用户信息
    return
  }

  return { user, isLoggedIn, getUserInfo, login }
})
